package com.cslg.ac.demo.dao.chat;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.cslg.ac.demo.dao.chat.po.ChatPO;

@Mapper
public interface ChatDAO {

	final String CHAT_TABLE = "e_chat";
	final String SELECT_FIELDS = " id, from_id, to_id, create_time, content ";
	
	@Insert({"insert into", CHAT_TABLE, "(from_id, to_id, content) values (#{fromId}, #{toId}, #{content})"})
	void insert(ChatPO chatPO);
	
	@Select({"select", SELECT_FIELDS, "from", CHAT_TABLE, "where id = #{id}"})
	ChatPO selectById(@Param("id") int id);
	
	@Select({"select id from", CHAT_TABLE,
		"where from_id = #{fromId} and to_id = #{toId} or from_id = #{toId} and to_id = #{fromId} order by id desc limit #{offset}, #{num}"})
	int[] select(@Param("fromId") int fromId, @Param("toId") int toId, @Param("offset") int offset, @Param("num") int num);
	
	@Select({"select last_insert_id()"})
	int selectLastInsertId();
}
